package com.game.src.main;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

public class Player {

	private double x;
	private double y;

	private double velX = 0;
	private double velY = 0;

	private double ticksToNextShot;
	private double ticksBetweenShots = 20;

	private Textures tex;

	boolean isShooting = false;

	private Game game;

	private int score = 0;
	private int health = 100;
	
	private boolean once = false;

	public Player(Game game, double x, double y, Textures tex) {
		this.x = x;
		this.y = y;
		this.tex = tex;
		this.game = game;
	}

	public void tick() {
		ticksToNextShot--;
		x += velX;
		y += velY;

		if (x <= 0) {
			x = 0;
		}
		if (y <= 0) {
			y = 0;
		}
		if (x >= 640 - 55) {
			x = 640 - 55;
		}
		if (y >= 480 - 64) {
			y = 480 - 64;
		}

		if (isShooting && ticksToNextShot < 0) {
			shoot();
			ticksToNextShot = ticksBetweenShots;
		}
	}

	public void shoot() {
		Controller c = game.getController();
		if(!once){
			c.addMessage(new Message("LEVEL UP", 60));
			once = true;
		}
		if (score <= 2500) {
			c.addBullet(new Bullet(getX() + 28, getY() - 13, tex));
			c.addBullet(new Bullet(getX() - 28, getY() - 13, tex));
		} else {
			c.addStrongBullet(new StrongBullet(getX() + 28, getY() - 13, tex));
			c.addStrongBullet(new StrongBullet(getX() - 28, getY() - 13, tex));
		}

		if (score > 1000) {
			if(!once){
				c.addMessage(new Message("LEVEL UP", 60));
				once = true;
			}
			if(!once){
				c.addMessage(new Message("LEVEL UP", 60));
				once = true;
			}
			ticksBetweenShots = 15;
			if (score > 6000) {
				ticksBetweenShots = 10;
				if (score > 10000) {
					ticksBetweenShots = 8;
					if (score > 12000 && score <= 30000) {
						c.addBullet(new Bullet(getX() - 28, getY() - 13, tex,
								-2, 8));
						c.addBullet(new Bullet(getX() + 28, getY() - 13, tex,
								+2, 8));
					}
					if (score > 30000) {
						c.addStrongBullet(new StrongBullet(getX() - 28,
								getY() - 13, tex, -2, 8));
						c.addStrongBullet(new StrongBullet(getX() + 28,
								getY() - 13, tex, +2, 8));
					}
				}
			}
		}
	}

	public void render(Graphics g) {
		g.drawImage(tex.player, (int) x, (int) y, null);
	}

	public double getX() {
		return x;
	}

	public double getY() {
		return y;
	}

	public void setX(double x) {
		this.x = x;
	}

	public void setY(double y) {
		this.y = y;
	}

	public void setVelX(double velX) {
		this.velX = velX;
	}

	public void setVelY(double velY) {
		this.velY = velY;
	}

	/**
	 * @return the isShooting
	 */
	public boolean isShooting() {
		return isShooting;
	}

	/**
	 * @param isShooting
	 *            the isShooting to set
	 */
	public void setShooting(boolean isShooting) {
		this.isShooting = isShooting;
	}

	/**
	 * @return the score
	 */
	public int getScore() {
		return score;
	}

	/**
	 * @param score
	 *            the score to set
	 */
	public void setScore(int score) {
		this.score = score;
	}

	/**
	 * @return the health
	 */
	public int getHealth() {
		return health;
	}

	/**
	 * @param health
	 *            the health to set
	 */
	public void setHealth(int health) {
		this.health = health;
	}

}
